package cn.edu.ahpu.pojo;

import cn.edu.ahpu.utils.Operate;

public class Formula {
	/**题号**/
	private int id;
	/**等式字符串**/
	private String equation;
	/**正确结果,其只有get方法，没有set，靠自身计算**/
	private float answer=0;
	/**等式类型**/
	private final Integer type;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getEquation() {
		return equation;
	}
	public void setEquation(String equation) {
		this.equation = equation;
		/*
		 * 计算结果
		 */
		switch(type) {
			case 1:
				this.answer=Operate.zeroToHundred(equation);
				break;
			case 2:
				this.answer=Operate.withBracket(equation);
				break;
			case 3://带分数运算,未写,待定
				break;
		}
	}
	public Float getAnswer() {
		return answer;
	}
	public Integer getType() {
		return type;
	}
	public Formula(Integer type) {
		this.type = type;
	}
	
	public Formula(String equation,Integer type) {
		this.equation = equation;
		this.type = type;
		/*
		 * 计算结果
		 */
		switch(type) {
			case 1:
				this.answer = Operate.zeroToHundred(equation);
				break;
			case 2:
				this.answer = Operate.withBracket(equation);
				break;
			case 3://带分数运算,未写,待定
				break;
		}
	}
	@Override
	public String toString() {
		return equation + "=" + answer;
	}
}
